//
//  AdvisoryBasicViewController.m
//  homeland
//
//  Created by SunShine on 13-10-25.
//  Copyright (c) 2013年 xzysun. All rights reserved.
//

#import "AdvisoryBasicViewController.h"
#import "AdvisoryDetailInfoCell.h"

@interface AdvisoryBasicViewController ()

@end

@implementation AdvisoryBasicViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"基本信息";
    [_tableView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIdentifier = @"AdvisoryListCell";
    AdvisoryDetailInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"AdvisoryDetailInfoCell" owner:self options:nil] objectAtIndex:0];
    }
    if (indexPath.row == 0) {
        cell.titleLabel.text = @"咨询事项";
        if ([NSNull null]==(NSNull *)_dataItem.title||[ @"" isEqualToString:_dataItem.title]) {
            _dataItem.title = @"";
        }
        cell.detailTextView.text = _dataItem.title;
    } else if (indexPath.row == 1) {
        cell.titleLabel.text = @"咨询时间";
        cell.detailTextView.text = [_dataItem.insertTime substringToIndex:10];
    } else if (indexPath.row == 2) {
        cell.titleLabel.text = @"姓名";
        cell.detailTextView.text = _dataItem.userName;
    } else if (indexPath.row == 3) {
        cell.titleLabel.text = @"手机号码";
        cell.detailTextView.text = _dataItem.phone;
    } else if (indexPath.row == 4) {
        cell.titleLabel.text = @"咨询内容";
        cell.detailTextView.text = _dataItem.content;
    } else if (indexPath.row == 5) {
        cell.titleLabel.text = @"受理部门";
        cell.detailTextView.text = _dataItem.unitName;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.detailTextView.contentInset = UIEdgeInsetsMake(-8, -8, -8, -8);
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 4) {
        if (_dataItem.content && _dataItem.content != (id)[NSNull null] && _dataItem.content.length > 0){
            CGFloat height = [self caculateHeightWithoutPaddingForString:_dataItem.content AndFontSize:14.0 AndWitdh:170.0];
            
            return MAX(52.0, height+46.0);
        }
    }
    return 52.0;
}
@end
